class BGM {
  constructor() {
    this.bgm = uni.getBackgroundAudioManager()
    this.isPlaying = false
  }
  
  init() {
    this.bgm.title = '时光花园'
    this.bgm.src = '/static/bgm.mp3'
    this.bgm.loop = true
    
    this.bgm.onPlay(() => {
      this.isPlaying = true
    })
    
    this.bgm.onPause(() => {
      this.isPlaying = false
    })
    
    this.bgm.onStop(() => {
      this.isPlaying = false
    })
  }
  
  play() {
    if (!this.isPlaying) {
      this.bgm.play()
    }
  }
  
  pause() {
    if (this.isPlaying) {
      this.bgm.pause()
    }
  }
}

export default new BGM() 